<?php
namespace Admin\Controller;
class GoodsController extends AdminController {
    //商品列表
    public function goods_list($category_id = 0, $brand_id = 0, $goods_attr ="", $is_on_sale = 1, $keywords = ""){
        //生成查询条件
        $map = array();
        if(!empty($category_id)){

        }

        if(!empty($brand_id)){

        }
        if(!empty($goods_attr)){

        }

        if(!empty($is_on_sale)){

        }

        if(!empty($keywords)){

        }

        //商品列表
        $goodsModel = D('good');
        $goods_list = $goodsModel->where($map)->select();

        //筛选-商品分类
        $select_category   = M('goods_category')->select();
        //筛选-商品品牌
        $select_brand      = M('goods_brand')->select();
        //筛选-商品特性
        $select_goods_attr = C('goods_recommend_attr');
        //筛选-是否上架
        $select_is_on_sale = C('goods_is_on_sale');

        //表格-表头
        $goods_table_head = C('goods_table_head');

        $this->assign('table_head',$goods_table_head);
        $this->assign('goods_list',$goods_list);
        $this->assign('select_category',$select_category);
        $this->assign('select_brand',$select_brand);
        $this->assign('select_goods_attr',$select_goods_attr);
        $this->assign('select_is_on_sale',$select_is_on_sale);
        $this->theme($this->template)->display('/goods_list');
    }

    //添加、修改商品
    public function goods_info($goods_id=0){
        $goodsModel = D('good');
        if(!IS_POST){
            if(empty($goods_id)){
                $page_name  = "添加新商品";
            }else{
                $page_name       = "编辑商品信息";
            }
            $goods_form_tab       = C('goods_form_tab');
            $goods_base_info      = C('goods_base_info');
            $goods_other_info     = C('goods_other_info');
            $goods_recommend_attr = C('goods_recommend_attr');
            $goods_is_on_sale     = C('goods_is_on_sale');

            //如果没有设置商品类型，商品属性标签不显示
            $goods_attr = M('attribute')->count();
            foreach($goods_form_tab as $key=>$val){
                if(empty($goods_attr)&&$val == '商品属性'){
                    unset($goods_form_tab[$key]);
                }
            }
            //查询商品分类
            $goods_category = M('goods_category')->select();

            $this->assign('page_name',$page_name);
            $this->assign('goods_id',$goods_id);
            $this->assign('form_tab',$goods_form_tab);
            $this->assign('base_info',$goods_base_info);
            $this->assign('other_info',$goods_other_info);
            $this->assign('recommend_attr',$goods_recommend_attr);
            $this->assign('is_on_sale',$goods_is_on_sale);
            $this->assign('goods_category',$goods_category);

            $this->theme($this->template)->display('/goods_info');
        }else{
            $data = I('post.');
            $result = $goodsModel->modify_goods_info($data);

            var_dump($result);
        }
    }

    //商品分类
    public function goods_category(){
        $goods_category = M('goods_category')->select();
        $category_table_head = C('category_table_head');

        $this->assign('goods_category',$goods_category);
        $this->assign('table_head',$category_table_head);
        $this->theme($this->template)->display('/goods_category');
    }

    //添加、修改商品分类
    public function category_info($category_id=0,$type='page'){
        if(!IS_POST){
            if($type == 'page'){
                if(empty($category_id)){
                    $page_name = "添加商品分类";
                }else{
                    $page_name = "编辑商品分类";
                }
                $category_info = C('category_info');
                $this->assign('category_info',$category_info);
                $this->assign('page_name',$page_name);
                $this->assign('category_id',$category_id);
                $this->theme($this->template)->display('/category_info');
            }else if($type == 'ajax'){
                $this->theme($this->template)->display('/ajax_category_info');
            }else{
                echo '并没有';
            }
        }else{
            $data = I('post.');
            if($type == 'page'){

            }else if($type == 'ajax'){

            }else{

            }
        }
    }

    //商品品牌
    public function goods_brand(){

    }

    //添加、修改商品品牌
    public function brand_info($brand_id=0,$type='page'){
        if(!IS_POST){
            if($type == 'page'){

            }else if($type == 'ajax'){

            }else{
                echo '并没有';
            }
        }else{

        }
    }

    //商品类型
    public function goods_type(){
        $type_table_head = C('type_table_head');
        $this->assign('table_head',$type_table_head);
        $this->theme($this->template)->display('/goods_type');
    }

    //添加、修改商品类型
    public function type_info($type_id=0){
        if(!IS_POST){
            if(empty($type_id)){

            }else{

            }
        }else{

        }
    }

    //批量管理
    public function goods_batch_manage(){

    }

    //商品推广
    public function goods_extend(){

    }

    //商品标签
    public function goods_tags(){

    }

    //删除商品
    public function goods_delete(){

    }


}